<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix='sec' uri='http://www.springframework.org/security/tags'%>
<head>
	<script type="text/javascript" src="scripts/boot.js"></script>
	<style type="text/css">
	    .errorText
	    {
	        color:red;
	    }
    </style>
</head>

<body>
	<form id="form1" method="post">
		<p style="margin-left: 30px;">
			<label>选择中心：</label>
			<input id="combo1" name="platformId" class="mini-combobox" style="width:150px;" textField="name" valueField="id" emptyText="请选择..."
    				url="group_platfrom_view.do" required="true" allowInput="false" showNullItem="true" nullItemText="请选择..."/> 
		</p>
		<p style="margin-left: 30px;">
			<label>组名称：</label>
			<input id="textbox1" name="name" class="mini-textbox" errorMode="none" onvalidation="checkValidation" requiredErrorText="组名称不能为空" required="true" vtype="rangeLength:0,50" style="margin-left:12px;width: 150px;" />
			<span style="margin-left:60px;" id="name_error" class="errorText" ></span>
		</p>
		<p style="margin-left: 30px;">
			<label>组备注：</label>
			<input id="textarea1" name="description" class="mini-textarea" style="width: 216px; "/>
		</p>
	</form>
    <p style="margin-left: 35px;">
    	<a class="mini-button" onclick="onOk" style="width:60px;margin-right:20px;">确定</a>
    	<a class="mini-button" onclick="onCancel" style="width:60px;">取消</a>
    </p>
</body>

<script type="text/javascript">
	mini.parse();
	var form = new mini.Form("form1");
	
	function SaveData() {
        var o = form.getData(true);
        form.validate();
        if (form.isValid() == false) return;
       	var platformId = mini.get("combo1").getValue();
   		var name = mini.get("textbox1").getValue();
   		$.post("center_include_group.do", {platformId: platformId, name: name}, function(text) {
   			if(text.success) {
   				save(o);
   			} else {
   				mini.alert('此组在当前中心下已存在!');
   			}
   		}, "json");
    }
	
	//判断同一中心下是否包含相同的组
	function save(o) {
		$.ajax({
            url: "medical_group_save.do",
			type: 'post',
			dataType: 'json',
            data: o,
            cache: false,
            success: function (text) {
            	if(text.success){
	            	window.CloseOwnerWindow("succ");
	            }else{
	            	mini.alert("数据错误，请重新添加");
	            }
            },
            error: function (jqXHR, textStatus, errorThrown) {
                alert(jqXHR.responseText);
                CloseWindow();
            }
        });
	}
	
	function onOk(e) {
        SaveData();
    }
	
	function SetData(data){
	     data = mini.clone(data);
	}
	
	function GetData() {
        var o = form.getData();
        return o;
    }
	
	function CloseWindow(action) {            
        if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
        else window.close();            
    }
	
	function onCancel(e) {
        CloseWindow("cancel");
    }

   	function updateError(e) {
	    var id =e.sender.name + "_error";
	    var el = document.getElementById(id);
	    if (el) {
	        el.innerHTML =e.errorText;
	    }
   	}
   
   	function checkValidation(e) {                  
  		updateError(e);
   	}
	
</script>